<html>
<head><meta charset="utf-8"><title>pr-53088 · t-compiler/wg-nll · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/index.html">t-compiler/wg-nll</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html">pr-53088</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="131002802"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002802" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002802">(Aug 06 2018 at 20:37)</a>:</h4>
<p><span class="user-mention" data-user-id="116009">@nikomatsakis</span> Changes are implemented now. Not sure how well it works for long type names</p>



<a name="131002805"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002805" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002805">(Aug 06 2018 at 20:37)</a>:</h4>
<div class="codehilite"><pre><span></span>error: unsatisfied lifetime constraints
  --&gt; $DIR/issue-49824.rs:22:9
   |
LL |       || {
   |       --
   |       ||
   |       |return type of closure is [closure@$DIR/issue-49824.rs:22:9: 24:10 x:&amp;&#39;2 mut i32]
   |       lifetime `&#39;1` represents this closure&#39;s body
LL | /         || {
LL | |             let _y = &amp;mut x;
LL | |         }
   | |_________^ requires that `&#39;1` must outlive `&#39;2`
   |
   = note: closure implements `FnMut`, so references to captured variables can&#39;t escape the closure

error: aborting due to previous error
</pre></div>



<a name="131002854"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002854" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002854">(Aug 06 2018 at 20:38)</a>:</h4>
<p>well</p>



<a name="131002858"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002858" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002858">(Aug 06 2018 at 20:38)</a>:</h4>
<p>I think the problem <em>there</em> is probably that we should try to identify that case</p>



<a name="131002865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002865">(Aug 06 2018 at 20:38)</a>:</h4>
<p>if nothing else, this version tells me what the problem is quite precisely though :)</p>



<a name="131002875"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002875" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002875">(Aug 06 2018 at 20:38)</a>:</h4>
<p>in particular, the closure holds on to a reference to <code>x</code></p>



<a name="131002900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002900">(Aug 06 2018 at 20:39)</a>:</h4>
<p>(also, I'm not 100% convinced this test <em>should</em> fail to compile)</p>



<a name="131002902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002902">(Aug 06 2018 at 20:39)</a>:</h4>
<p>that .. kind of seems like a bug</p>



<a name="131002905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002905">(Aug 06 2018 at 20:39)</a>:</h4>
<p>but not related to your PR, obviously</p>



<a name="131002917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002917">(Aug 06 2018 at 20:39)</a>:</h4>
<p>anyway, TL;DR I still consider that an improvement on what was there before, because it gives you enough information to solve the problem, if you know how to interpret it; but it's not a final goal in that we should break it down for the user more</p>



<a name="131002976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002976">(Aug 06 2018 at 20:40)</a>:</h4>
<p>(we should probably also investigate <em>why</em> <code>issue-49824.rs</code> is failing to compile, which seems like an NLL-complete bug)</p>



<a name="131002981"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131002981" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131002981">(Aug 06 2018 at 20:40)</a>:</h4>
<p>I feel like we maybe had a bug on this?</p>



<a name="131003020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003020">(Aug 06 2018 at 20:41)</a>:</h4>
<p>I think there is a recent one opened by Felix</p>



<a name="131003112"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003112" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003112">(Aug 06 2018 at 20:43)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/53040" target="_blank" title="https://github.com/rust-lang/rust/issues/53040">#53040</a></p>



<a name="131003214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003214">(Aug 06 2018 at 20:44)</a>:</h4>
<p>ah yes and I see I wrote this which seems relevant too :)</p>



<a name="131003215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003215">(Aug 06 2018 at 20:44)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/issues/49824#issuecomment-384391152" target="_blank" title="https://github.com/rust-lang/rust/issues/49824#issuecomment-384391152">https://github.com/rust-lang/rust/issues/49824#issuecomment-384391152</a></p>



<a name="131003253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003253">(Aug 06 2018 at 20:45)</a>:</h4>
<p>ok so</p>



<a name="131003279"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003279" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003279">(Aug 06 2018 at 20:46)</a>:</h4>
<p>I would say we should try to identify this case and give a nice error</p>



<a name="131003328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003328">(Aug 06 2018 at 20:46)</a>:</h4>
<p>it seems sort of related to <a href="https://github.com/rust-lang/rust/issues/51026" target="_blank" title="https://github.com/rust-lang/rust/issues/51026">https://github.com/rust-lang/rust/issues/51026</a> as well</p>



<a name="131003334"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003334" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003334">(Aug 06 2018 at 20:46)</a>:</h4>
<p>though it may not be precisely the same scenario</p>



<a name="131003366"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003366" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003366">(Aug 06 2018 at 20:47)</a>:</h4>
<p>specifically I think the scenario would be:</p>



<a name="131003382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003382">(Aug 06 2018 at 20:47)</a>:</h4>
<ul>
<li>if the one region appears as the lifetime of an implicit closure upvar reference (here, the reference to <code>x</code>)</li>
</ul>



<a name="131003438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003438">(Aug 06 2018 at 20:48)</a>:</h4>
<ul>
<li>and the other region is the closure body</li>
</ul>



<a name="131003451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003451">(Aug 06 2018 at 20:48)</a>:</h4>
<p>then we want to say something like "this closure captures <code>x</code> by reference but then escapes its creating stack frame"</p>



<a name="131003453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003453">(Aug 06 2018 at 20:48)</a>:</h4>
<p>and suggest using "move"</p>



<a name="131003466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003466">(Aug 06 2018 at 20:49)</a>:</h4>
<p>actually the message from borrowck-escaping-closure-error-1 is probably exactly what we want</p>



<a name="131003467"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003467" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003467">(Aug 06 2018 at 20:49)</a>:</h4>
<p>so maybe this really <em>is</em> the same case</p>



<a name="131003477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003477">(Aug 06 2018 at 20:49)</a>:</h4>
<div class="codehilite"><pre><span></span>error[E0373]: closure may outlive the current function, but it borrows `books`, which is owned by the current function
  --&gt; $DIR/borrowck-escaping-closure-error-1.rs:23:11
   |
LL |     spawn(|| books.push(4));
   |           ^^ ----- `books` is borrowed here
   |           |
   |           may outlive borrowed value `books`
help: to force the closure to take ownership of `books` (and any other referenced variables), use the `move` keyword
   |
LL |     spawn(move || books.push(4));
   |           ^^^^^^^
</pre></div>



<a name="131003491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003491">(Aug 06 2018 at 20:49)</a>:</h4>
<p>probably what we want is to to skip the "...and the other region is the closure body" check</p>



<a name="131003498"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003498" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003498">(Aug 06 2018 at 20:49)</a>:</h4>
<p>and just print something like whenever the other region is "some free region"</p>



<a name="131003544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003544">(Aug 06 2018 at 20:50)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> does that make sense?</p>



<a name="131003869"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003869" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003869">(Aug 06 2018 at 20:57)</a>:</h4>
<p>Yes. You might want to leave a note for this somewhere so it doesn't get lost.</p>



<a name="131003963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131003963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131003963">(Aug 06 2018 at 20:58)</a>:</h4>
<p>I left it in the issue <a href="https://github.com/rust-lang/rust/issues/51026" target="_blank" title="https://github.com/rust-lang/rust/issues/51026">https://github.com/rust-lang/rust/issues/51026</a>, which is assigned to you actually</p>



<a name="131004843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122657-t-compiler/wg-nll/topic/pr-53088/near/131004843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/122657-t-compiler/wg-nll/topic/pr-53088.html#131004843">(Aug 06 2018 at 21:19)</a>:</h4>
<p><span class="user-mention" data-user-id="116118">@Matthew Jasper</span> so looking at <a href="https://github.com/rust-lang/rust/issues/51354" target="_blank" title="https://github.com/rust-lang/rust/issues/51354">https://github.com/rust-lang/rust/issues/51354</a>, I think that is also a case where this error message would apply</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>